<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let str = 'sdfrsdfrfrrfghy';

        function charFrequency(s) {
            let freqMap = {};
            for (let char of s) {
                freqMap[char] = (freqMap[char] || 0) + 1;
            }
            return freqMap;
        }

        function mostFrequentChar(s) {
            let frequencies = charFrequency(s);
            let maxChar = '';
            let maxCount = 0;

            for (let char in frequencies) {
                if (frequencies[char] > maxCount) {
                    maxCount = frequencies[char];
                    maxChar = char;
                }
            }
            console.log('出现最多的字母是:'+ maxChar+ '出现次数:'+ maxCount);
        }

        mostFrequentChar(str);
    </script>
</body>
</html>
